using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using SpringWaterDataAccess;

namespace client
{
    /// <summary>
    /// Summary description for bloggerarticles.
    /// </summary>
    public partial class forumsEdit : System.Web.UI.Page
    {

        protected long userID = 0;

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Request.QueryString["UserID"] == null)
                return;

            userID = Convert.ToUInt16(Request.QueryString["UserID"]);
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            ForumDataAccess da = new ForumDataAccess();
         
           DataSet ds = da.GetBBSPostsByUserID(userID); 

            MyRepeater.DataSource = ds;
            MyRepeater.DataBind();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion

        protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BindData();
        }

        protected void Button5_Click1(object sender, EventArgs e)
        {
            foreach (RepeaterItem myitem in MyRepeater.Items)
            {
                foreach (Control c in myitem.Controls)
                {
                    if (c is CheckBox)
                    {
                        CheckBox cb = (CheckBox)c;

                        if ((cb.Checked))
                        {
                            // Each row has a invisible Label for dispalying word ID
                            Label idLabel = (Label)myitem.FindControl("Label1");

                            if (idLabel != null)
                            {
                                //Response.Write(idLabel.Text + "<br>");
                                ForumDataAccess da = new ForumDataAccess();
                                da.DeletePost(Convert.ToInt16(idLabel.Text));
                            }
                        }
                    }
                }
            }
            BindData();
        }

        protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
              Button5_Click1(sender, e);
        }
    }
}
